<?php

class Globals {

	public static $server;
	public static $db;
	
	public static function init() {
		self::$server = null;
		self::$db = null;
		
		if (!isset($_SERVER)) die("SERVER not set.");
		if (!is_array($_SERVER)) die("SERVER not an array.");
		$server_name = array_key_exists($_SERVER['SERVER_NAME'], $_SERVER) ? $_SERVER['SERVER_NAME'] : "localhost";
		
		switch ($server_name) {
		case "127.0.0.1":
		case "localhost":
			self::$server = "http://" . $server_name . "/panospanos2/";
			self::$db = mysqli_connect($_SERVER["SERVER_NAME"], "root", "", "hairsalon");
			mysqli_set_charset(self::$db, "utf8");
			break;
		//case ip του μεμακρυσμένου server
		//case domain name του μεμακρυσμένου server
		
		default :
			die("the server '" . $server_name . "' is unknown server");
		}
	}
	
}
/*
class Globals {
	public $server;
	public $db;
	public $xristis;
	
	public function __construct() {
		if (!isset($_SERVER)) {
			die("_SERVER: not set");
		}
		
		if (!is_array($_SERVER)) {
			die("_SERVER not an array");
		}
		
		if (!array_key_exists("SERVER_NAME", $_SERVER)) {
			die("SERVER_NAME: index not found");
		}

		switch ($_SERVER["SERVER_NAME"]) {
		case "localhost":
		case "127.0.0.1":
			$this->server = "http://" . $_SERVER["SERVER_NAME"] . "/randevou/";
			$this->db = mysqli_connect($_SERVER["SERVER_NAME"], "root", "", "randevou");
			break;
		default:
			die($_SERVER["SERVER_NAME"] . ": cannot open database");
			break;
		}
		
		@mysqli_set_charset($this->db, 'UTF8');
		if ($this->db === FALSE) {
			die("database connect fail");
		}

	}

	public function set_xristis() {
		if (!isset($_SESSION)) {
			die("_SESSION: not set");
		}

		if (!is_array($_SESSION)) {
			die("_SESSION: not an array");
		}

		if (!array_key_exists("login", $_SESSION)) {
			$this->xristis = new Xristis();
			return;
		}

		$this->xristis = new Xristis($_SESSION['login']);
		if (!isset($this->xristis->login)) {
			unset($_SESSION['login']);
		}
	}

	public function check_xristis() {
		$this->set_xristis();
		if ($this->is_xristis()) {
			return;
		}

		die("Απροσδιόριστος χρήστης");
	}

	public function is_xristis() {
		if (!isset($this->xristis)) {
			return FALSE;
		}

		if (!isset($this->xristis->login)) {
			return FALSE;
		}

		return TRUE;
	}

	public function not_xristis() {
		return (!$this->is_xristis());
	}

	public static function perastike($parametros, $verbose = TRUE) {
		if (!isset($_REQUEST)) {
			die("_REQUEST: not set");
		}
		
		if (!is_array($_REQUEST)) {
			die("_REQUEST not an array");
		}
		
		if (array_key_exists($parametros, $_REQUEST)) {
			return TRUE;
		}

		if ($verbose) {
			print $parametros . ": index not found";
		}

		return FALSE;
	}
	
	public static function parametros($parametros) {
		if (self::perastike($parametros)) {
			return $_REQUEST[$parametros];
		}

		die(0);
	}
	
	public function asfales($s) {
		return mysqli_real_escape_string($this->db, $s);
	}

	public function query($query) {
		$result = ($this->sqlerror ? mysqli_query($this->db, $query)
			: @mysqli_query($this->db, $query));
		if ($result === FALSE) {
			print "sql error";
			if ($this->sqlerror) {
				print " (" . $query . ")";
			}
			die(2);
		}
		return $result;
	}

	public static function json_safe($s) {
		return str_replace("'", "\\'", $s);
	}

	public static function get_line($fp) {
		$line = fgets($fp);
		if (!$line) { return FALSE; }

		$line = preg_replace("/[\r\n]/", "", $line);
		return $line;
	}

	public static function put_line($fp, $s) {
		return fwrite($fp, $s . "\n");
	}
}

mb_internal_encoding('UTF-8');
mb_regex_encoding('UTF-8');

global $globals;
$globals = new Globals();
*/
?>
